#!/bin/sh

alias curl="curl -stderr"
export dir=data-`date  '+%Y-%m-%d'`
rm -f -r $dir *.html
\rm -f "./intraday/*"
mkdir $dir

echo "TA indicator last trading day......"
curl http://www.datawm.com/nastocks/stockcharts/welcome.html |sed 's/href/\n/g' > TAPattern.html
cat TAPattern.html |tr "<" "\n" |grep qry |cut -d'"' -f2 > tmp$$
for chart in `cat tmp$$`
do
    export chart2=`echo $chart | cut -d'.' -f1`
    curl "http://www.datawm.com/nastocks/stockcharts/$chart" |egrep -o "<br/>[A-Z]+<br/>" |egrep -o "[A-Z]+" > ./$dir/$chart2
done

curl  http://www.datawm.com/nastocks/specials/welcome.html|sed 's/href/\n/g' > SpecialTreat.html
cat SpecialTreat.html |tr "<" "\n" |grep qry |cut -d'"' -f2 > tmp$$
for chart in `cat tmp$$`
do
    export chart2=`echo $chart | cut -d'.' -f1`
    curl "http://www.datawm.com/nastocks/specials/"$chart |egrep -o "<br/>[A-Z]+<br/>" |egrep -o "[A-Z]+" > ./$dir/$chart2
done

curl http://www.datawm.com/nastocks/clearstationFilters/welcome.html | sed 's/href/\n/g' >ClearStation.html
cat ClearStation.html |tr "<" "\n" |grep "\"clearstation" |cut -d">" -f2 > tmp$$
for chart in `cat tmp$$`
do
    export chart2=`echo $chart | cut -d'.' -f1`
    curl "http://www.datawm.com/nastocks/clearstationFilters/"$chart |egrep -o "<br/>[A-Z]+<br/>" |egrep -o "[A-Z]+"  > ./$dir/$chart2
done

curl  http://www.datawm.com/nastocks/stockchartsFilters/welcome.html |sed 's/href/\n/g' >StockCharts.html
cat StockCharts.html |tr "<" "\n" |grep "stockcharts" |cut -d">" -f2 > tmp$$
for chart in `cat tmp$$`
do
    export chart2=`echo $chart | cut -d'.' -f1`
    curl "http://www.datawm.com/nastocks/stockchartsFilters/"$chart |egrep -o "<br/>[A-Z]+<br/>" |egrep -o "[A-Z]+" > ./$dir/$chart2
done

curl  http://www.datawm.com/nastocks/close2rangeHigh/welcome.html |sed 's/href/\n/g' >Close2High.html
cat Close2High.html |tr "<" "\n" |grep ".txt.html" |cut -d">" -f2 > tmp$$
for chart in `cat tmp$$`
do
    export chart2=`echo $chart | cut -d'.' -f1`
    curl "http://www.datawm.com/nastocks/close2rangeHigh/"$chart |egrep -o "<br/>[A-Z]+<br/>" |egrep -o "[A-Z]+" > ./$dir/$chart2
done

curl  "http://www.datawm.com/nastocks/intraday/" |sed 's/href/\n/g' >Intraday.html
cat Intraday.html |tr "<" "\n" |grep qry |cut -d">" -f2 |grep qry > tmp$$
for chart in `cat tmp$$`
do
    export chart2=`echo $chart | cut -d'.' -f1`
    curl "http://www.datawm.com/nastocks/intraday/$chart" |egrep -o "<br/>[A-Z]+<br/>" |egrep -o "[A-Z]+" > ./$dir/$chart2
done

>TodayLongList
cat $dir/*Down-LargeStocks*     >> TodayLongList
cat $dir/*Oversold*             >> TodayLongList
cat $dir/*Down2MaxDnDays*       >> TodayLongList
cat $dir/*BottomFish*           >> TodayLongList
cat TodayLongList |sort |uniq > tmp$$
cp tmp$$ TodayLongList

>TodayShortList
cat $dir/*shorttarget*  >> TodayShortList
cat $dir/*Rise2MaxUpDays*  >> TodayShortList
cat $dir/*Overbought*  >> TodayShortList
cat TodayShortList |uniq |sort > tmp$$
cp tmp$$ TodayShortList

curl "http://www.datawm.com/nastocks/stockchart_dailyAlert.txt" > stockchart.dat
curl "http://www.datawm.com/nastocks/clearstation-outputFile.txt" > clearstation.dat

mv tmp$$ 
